<?php
header ( 'Content-Type:text/html; charset=UTF-8' );
session_start ();
$name = $_REQUEST ['username'];
$pass = $_REQUEST ['password'];
$pdo = new PDO ( 'mysql:dbname=crm; charset=utf8', 'root' );
$s = $pdo->prepare ( 'select * from username' );
$s->execute ();
$data = $s->fetchAll ( PDO::FETCH_NAMED );
foreach ( $data as $value ) {
	if ($name == $value ['name']) {
		break;
	}
}
if ($name != $value ['name']) {
	echo json_encode ( array (
			'zt' => false,
			'fhwb' => '用户不存在' 
	) );
} elseif ($pass == $value ['password']) {
	$_SESSION ['user'] = $name;
	if($value ['sf']=='guanl'){
		$_SESSION ['sf'] = 'guanl';
		echo json_encode ( array (
				'zt' => true,
				'fhwb' => '登录成功',
				'mz'=>'管理员'.$name
		) );
	}else{
		$_SESSION ['sf'] = 'keh';
		echo json_encode ( array (
				'zt' => true,
				'fhwb' => '登录成功',
				'sf'=>'keh',
				'mz'=>'客户'.$name,
		) );
	}
	
} else {
	echo json_encode ( array (
			'zt' => false,
			'fhwb' => '密码错误' 
	) );
}
?>
